/*
**************************************************************************************
*Myriad Engine                                                                       *
*Copyright (C) 2006-2007, 5d Studios (www.5d-Studios.com)                            *
*                                                                                    *
*This library is free software; you can redistribute it and/or                       *
*modify it under the terms of the GNU Lesser General Public                          *
*License as published by the Free Software Foundation; either                        *
*version 2.1 of the License, or (at your option) any later version.                  *
*                                                                                    *
*This library is distributed in the hope that it will be useful,                     *
*but WITHOUT ANY WARRANTY; without even the implied warranty of                      *
*MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                   *
*Lesser General Public License for more details.                                     *
*                                                                                    *
*You should have received a copy of the GNU Lesser General Public                    *
*License along with this library; if not, write to the Free Software                 *
*Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA      *
**************************************************************************************
*/
package leola.types;

import java.util.ArrayList;
import java.util.List;


/**
 * An array
 * 
 * @author Tony
 *
 */
public class LeoArray extends LeoObject {

	/**
	 * Array
	 */
	private List<LeoObject> array;
	
	/**
	 */
	public LeoArray() {
		this(new ArrayList<LeoObject>());
	}

	/**
	 * @param array
	 */
	public LeoArray(List<LeoObject> array) {
		super(LeoType.ARRAY);
		
		this.array = array;
	}
	
	/* (non-Javadoc)
	 * @see leola.types.LeoObject#toString()
	 */
	@Override
	public String toString() {
		return this.array.toString();
	}
	
	/**
	 * Adds an object
	 * @param obj
	 */
	public void add(LeoObject obj) {
		this.array.add(obj);
	}
	
	/**
	 * Gets an element
	 * @param i
	 * @return
	 */
	public LeoObject get(int i) {
		return this.array.get(i);
	}
	
	/**
	 * @return the size of the array
	 */
	public int size() {
		return this.array.size();
	}
	
	/**
	 * Sets an element
	 * @param index
	 * @param obj
	 */
	public void set(int index, LeoObject obj) {
		this.array.set(index, obj);
	}
	
	/**
	 * Sets the element at the provided index
	 * @param index
	 * @param obj
	 */
	public void set(LeoNumber index, LeoObject obj) {
		this.array.set( (int)index.getNumber(), obj);
	}
	
	/**
	 * @return the array
	 */
	public List<LeoObject> getArray() {
		return array;
	}
	
	/* (non-Javadoc)
	 * @see leola.types.LeoObject#clone()
	 */
	@Override
	public LeoObject clone() {
		return new LeoArray(new ArrayList<LeoObject>(this.array));
	}

	/* (non-Javadoc)
	 * @see leola.types.LeoObject#eq(leola.types.LeoObject)
	 */
	@Override
	public boolean eq(LeoObject other) {
		return this.array.equals(other);
	}

	/* (non-Javadoc)
	 * @see leola.types.LeoObject#getValue()
	 */
	@Override
	public Object getValue() {
		return this; /*this.array;*/
	}

	/* (non-Javadoc)
	 * @see leola.types.LeoObject#gt(leola.types.LeoObject)
	 */
	@Override
	public boolean gt(LeoObject other) {
		return false;
	}

	/* (non-Javadoc)
	 * @see leola.types.LeoObject#lt(leola.types.LeoObject)
	 */
	@Override
	public boolean lt(LeoObject other) {
		return false;
	}

}
